<template>
	<view class="content">
		<div class="warp">
			<div class="warp-t">个人基本资料</div>
			<div class="warp-c">
				<view class="item">
					<div class="item-l">
						<image mode="aspectFill" src="../../../static/img/monitor/archived.png"></image>
						<text>{{userInfo && userInfo.realName || ''}}</text>
					</div>
					<div class="item-c">
						<p>个人基本信息表</p>
						<p>表单编号：{{userInfo && userInfo.sn || ''}}</p>
						<p>存档时间：{{userInfo && userInfo.createTime ? filterData2(userInfo.createTime) : ''}}</p>
					</div>
				</view>
			</div>
		</div>
		<div class="warp">
			<div class="warp-t"><span>问卷资料</span><span v-if="!questionInfo" @click="toAddQuestion">暂无可用问卷</span></div>
			<div class="warp-c" v-if="questionInfo">
				<view class="item" >
					<div class="item-l">
						<image mode="aspectFill" :src="!questionInfo.sources || questionInfo.sources == 3 ?'../../../static/img/monitor/not-archived.png':'../../../static/img/monitor/archived.png'"></image>
						<text>{{questionInfo && questionInfo.signName ? questionInfo.signName : questionInfo && questionInfo.realName}}</text>
					</div>
					<div class="item-c">
						<p>生活方式问卷</p>
						<p>问卷编号：{{questionInfo && questionInfo.questionNumber}}</p>
						<p>存档时间：{{questionInfo && questionInfo.questionTime}}</p>
					</div>
				</view>
			</div>
		</div>
		<div class="warp">
			<div class="warp-t"><span>体检报告</span><span @click="dialog = true">选择体检报告</span></div>
			<div class="item-c" v-if="reportInfo">
				<view class="item" >
					<div class="item-l">
						<image mode="aspectFill" :src="!reportInfo.sources || reportInfo.sources == 3 ?'../../../static/img/monitor/not-archived.png':'../../../static/img/monitor/archived.png'"></image>
						<text>{{reportInfo && reportInfo.signName ?  reportInfo.signName : reportInfo && reportInfo.realName}}</text>
					</div>
					<div class="item-c">
						<p>体检报告{{reportInfo.type == 2 ? '(PDF)':'(图片)'}}</p>
						<p>体检机构：{{reportInfo.medicalName}}</p>
						<p>体检时间：{{reportInfo.updateTime}}</p>
					</div>
				</view>
			</div>
		</div>
		
		<button :class="[!userInfo || !questionInfo || !reportInfo?'':'on','submit']" @click="submit">申请评估</button>
		<u-popup class="dialog" v-model="dialog"  mode="bottom">
			<!-- <u-icon name="close" color="#333" size="32" ></u-icon> -->
			<view class="scroll">
				<view class="item" v-for="(item, index) in medicalList" :key="index">
					<u-radio-group v-model="radiovalue">
						<u-radio @change="radioChange($event,item)" :name="item.id">
							<div class="item-l">
								<image mode="aspectFill" src="../../../static/img/monitor/archived.png"></image>
								<text>{{userInfo && userInfo.realName}}</text>
							</div>
							<div class="item-c">
								<p>体检报告{{item.type == 2 ? '(PDF)':'(图片)'}}</p>
								<p>体检机构：{{item.medicalName}}</p>
								<p>体检时间：{{item.updateTime}}</p>
							</div>
						</u-radio>
					</u-radio-group>
				</view>
			</view>
			<div class="btns">
				<button @click="[dialog = false,radiovalue = '' , reportInfo='']">取消</button>
				<button @click="dialog = false">确定</button>
			</div>
		</u-popup>
	</view>
</template>
<script>
	import {filterData2} from '@/static/js/filter.js'
	export default {
		data() {
			return {
				userInfo:'',
				questionInfo:'',
				dialog:false,
				radiovalue:'',
				medicalList:[],
				reportInfo:''
			};
		},
		onLoad(){
			this.$api.newestUserInfo().then((res)=>{
				this.userInfo = res.data.result;
			})
			this.$api.newestQuestionnaire({questionType:1}).then((res)=>{
				this.questionInfo = res.data.result
			})
			this.$api.newestMedical().then((res)=>{
				this.medicalList = res.data.result
			})
			
		},
		methods:{
			filterData2,
			chooseReport(){
				
			},
			toAddQuestion(){
				uni.navigateTo({
					url: '/pages/monitor/assessment/investigation'
				})
			},
			radioChange(a,e){
				this.reportInfo = e
			},
			submit(){
				if(!this.userInfo || !this.questionInfo || !this.reportInfo){
					return;
				}
				const data = {
					assessType:1,
					medicalName:this.reportInfo.medicalName,
					questionId:this.questionInfo.id,
					questionNumber:this.questionInfo.questionNumber,
					questionTime:this.questionInfo.questionTime,
					reportDate:this.reportInfo.updateTime,
					reportId:this.reportInfo.id,
					reportNumber:this.reportInfo.medicalNumber,
					userNumber: this.userInfo.sn,
				}
				this.$api.Assessinsert(data).then((res)=>{
					if(res.data.returnCode == 200){
						uni.navigateTo({
							url: '/pages/monitor/tcm/list?type=2'
						})
					}else{
						uni.showToast({
							title: res.data.message,
							icon: 'none'
						})
					}
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
.content{
	min-height: 100vh;
	background: #F8F8F8;
	.warp{
		margin-bottom: 30upx;
	}
	.warp-t{
		padding:0 25upx;
		font-weight: bold;
		display: flex;
		justify-content: space-between;
		span:nth-of-type(2){
			color: #0066CC;
		}
	}
	.item{
		display: flex;
		padding: 47upx 25upx;
		background: #fff;
		margin-bottom: 24upx;
		width: 100%;
		&-l{
			position: relative;
			image{
				width: 92upx;
				height: 106upx;
				margin-right: 48upx;
				margin-top: 10upx;
			}
			text {
				width: 92upx;
				position: absolute;
				bottom: 16upx;
				color: #FFFFFF;
				font-size: 18upx;
				left: 0;
				overflow: hidden;    
				text-overflow:ellipsis;    
				white-space: nowrap;
				display: block;
				text-align: center;
			}
		}
		&-c{
			flex:1;
			font-size: 28upx;
			line-height: 1.5;
			&:nth-of-type(1){
				font-weight: bold;
				font-size: 30upx;
			}
		}
		&-r{
			font-size: 26upx;
			&.not-archived{
				color: #1A85E9;
			}
			&.archived{
				color: #38CB97;
			}
		}
	}
}
.submit{
	background: #C3C3C3;
	width: 500upx;
	height: 70upx;
	line-height: 70upx;
	border-radius: 70upx;
	font-size: 30upx;
	color: #fff;
	margin-top: 90upx;
	&.on{
		background: #38CB97;
	}
}
/deep/ .u-drawer-content{
	height: 100vh !important;
	.btns{
		display: flex;
		justify-content: space-between;
		width: 100%;
		position: fixed;
		bottom: 20upx;
		button{
			background: #38CB97;
			width: 300rpx;
			height: 70upx;
			line-height: 70upx;
			border-radius: 70upx;
			font-size: 30upx;
			color: #fff;
			&:nth-of-type(1){
				border: 1px solid #38CB97;
				background: unset;
				color: #38CB97;
			}
		}
	}
}
/deep/ .u-radio__label{
	display: flex;
	margin-left: 40upx;
	border-bottom: 1upx solid #EEEEEE;
	padding: 30upx 0;
	flex:1;
}
/deep/ .uni-scroll-view .item{
	padding: 0 48upx !important;
}
/deep/ .u-radio-group{
	width: 100% !important;
	.u-radio{
		width: 100% !important;
	}
}
.scroll{
	max-height: calc(100vh - 120upx);
	overflow-y: auto;
}
.dialog{
	.u-icon{
		position: absolute;
		right: 30rpx;
		top:30rpx;
	}
}
</style>
